how to access mysql table from wamp database using this php code? [migrated]

Posted by user3909877 on Pro Webmasters See other posts from Pro Webmasters or by user3909877
Published on 2014-08-23T09:45:52Z Indexed on 2014/08/23 10:36 UTC
Read the original article Hit count: 128

Filed under:
|
|
|
|

how to access tables from database by using php in wamp server.i have done the following code but its not working for some reason.is there anything to put in 'action=""'.it is not giving any error but displaying the same page.i want to display table from database on any different entry in dropdown menu and pressing search button..

<p class="h2">Quick Search</p>
    <div class="sb2_opts">
     <p>
   </p>
<form method="post" action="" >
 <p>Enter your source and destination.</p>
<p>
    From:</p>
<select name="from">
<option value="Islamabad">Islamabad</option>
<option value="Lahore">Lahore</option>
<option value="murree">Murree</option>
<option value="Muzaffarabad">Muzaffarabad</option>
</select>
<p>
    To:</p>
   <select name="To">
<option value="Islamabad">Islamabad</option>
<option value="Lahore">Lahore</option>
<option value="murree">Murree</option>
<option value="Muzaffarabad">Muzaffarabad</option>
</select>
<input type="submit" value="search" /> 
</form>
</form> </table>

<?php


if(isset($_POST['from']) and isset($_POST['To'])) {
$from = $_POST['from'] ;
$to = $_POST['To'] ;
$table = array($from, $to);
$con=mysqli_connect("localhost");
$mydb=mysql_select_db("homedb"); 
if (mysqli_connect_errno()) 
{ 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
}


switch ($table) {
  case array ("Islamabad", "Lahore") :
$result = mysqli_query($con,"SELECT * FROM flights");
echo "</flights>";                                    //table name is flights


 break;
  case array ("Islamabad", "Murree") :

$result = mysqli_query($con,"SELECT * FROM `isb to murree`");
echo "</`isb to murree`>";                                     //table name isb to murree
  ;
 break;
  case array ("Islamabad", "Muzaffarabad") :

$result = mysqli_query($con,"SELECT * FROM `isb to muzz`");
echo "</`isb to muzz`>";
 break;
//.....
//......
default:
echo "Your choice is nor valid !!";
}

}
mysqli_close($con);
?>

© Pro Webmasters or respective owner

Related posts about php

Related posts about html